home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
QuickTime 1.0 for Developers
/
QuickTime 1.0 for Developers.iso
/
Programming Stuff
/
Sample Code
/
BareBones
/
Bare Bones Prev.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-09-05
|
4KB
|
117 lines
/**************************************************
*
* Bare Bones Player (Version That Uses Standard Preview)
* This program demonstrates how to open a movie file
* and play it in a window
*
* Rich Williams 12/90 Chris Thorman 3/18/91
* Updated 2/91, 3/91 Updated 3/18/91
* Updated to 4.04 interfaces
* Updated to MPW/Think 5.0/DSG interfaces 9/91 Chris Thorman
*
***************************************************/
#include "Movies.h"
#include <Memory.h>
#include <Fonts.h>
#include <OSEvents.h>
#include <Menus.h>
/**************************************************
* Variables
***************************************************/
Movie theMovie; /* Info about the movie returned by OpenMovie*/
Rect dispBounds;
WindowPtr movieWindow; /* Window to play the movie in */
OSErr theErr;
/* Stuff for opening the file */
FSSpec mySpec; /* File System record for the file */
short resRefNum; /* Resource reference number when opening the file */
Point dlgPos = {100,100}; /* Position the dialog box */
short numtypes = 1;
SFTypeList types = {'MooV'};
StandardFileReply sfr; /* New-style SF reply */
void PlayTheMovie(void);
/**************************************************
*
* main()
* This is where everything happens
*
***************************************************/
main()
{
MaxApplZone(); /* Initialize the managers */
InitGraf(&qd.thePort);
InitFonts();
FlushEvents(everyEvent, 0);
InitWindows();
InitMenus();
InitCursor();
if(theErr = EnterMovies()) /* Start up the movie tools */
return; /* Bail out if error. A nice person would put an alert up */
PlayTheMovie(); /* Do it */
ExitMovies();
}
/**************************************************
*
* PlayTheMovie() Opens and plays Movie File
*
***************************************************/
void
PlayTheMovie(void)
{
/* Find out which movie file to play */
StandardGetFilePreview(0, numtypes, types, &sfr);
if (!sfr.sfGood) return; /* Return if no selection */
/* No need to make an FSSpec record for the file
because StandardGetFilePreview returns one as part of its StandardFileReply */
/* First open the movie file */
if (theErr = OpenMovieFile(&(sfr.sfFile), &resRefNum, 0))
return; /* Bail out if it didn't work */
if (theErr = NewMovieFromFile( &theMovie,resRefNum, nil, nil,0, nil ))
return; /* Bail out if it didn't work */
/* Get the bounds for the movie and make sure the top left is 0,0 */
/* so the movie won't be offset within the window */
GetMovieBox( theMovie, &dispBounds);
OffsetRect(&dispBounds,-dispBounds.left,-dispBounds.top);
SetMovieBox(theMovie, &dispBounds);
/* Set up the window for the movie to play in */
OffsetRect(&dispBounds,100,100); /* Make sure window not under menu bar */
movieWindow = NewCWindow(0L,&dispBounds,(StringPtr)sfr.sfFile.name,true,0,(WindowPtr)-1L,false,0L); /* Make a new window */
SetPort(movieWindow);
SetMovieGWorld(theMovie,nil,nil); /* Play the movie in the window */
/* Now we're ready to play the movie */
GotoBeginningOfMovie(theMovie);
PrerollMovie(theMovie,0,0); /* Get the movie ready to play */
SetMovieActive(theMovie,true);
StartMovie(theMovie); /* Start the movie */
/* Play the movie until done or the mouse button has been pressed */
while ( !IsMovieDone(theMovie) && !Button() )
MoviesTask(theMovie,0);
/* Clean up and go home */
DisposeMovie(theMovie); /* Get rid of the movie */
CloseMovieFile(resRefNum);
}